package exam;

public class day6 {

    public class ListNode {
    int val;
    ListNode next = null;
    public ListNode(int val) {
      this.val = val;
    }
  }

    public static void main(String[] args) {
        System.out.println(solve("1", "99"));
    }

    public ListNode addInList (ListNode head1, ListNode head2) {
int []arr1=new int[1000001];
int []arr2=new int[1000001];
ListNode cur1=head1;
ListNode cur2=head2;
int len1=0;
int len2=0;
while(cur1!=null){
    arr1[len1++]= cur1.val;
}
        while(cur2!=null){
            arr2[len2++]= cur2.val;
        }

        ListNode head=len1>len2?head1:head2;

        int []arr3=new int[1000001];
        int len=Math.max(len1,len2);
        int l=len;
        int cu=0;
        while (len2>0&&len1>0){
            int t=arr1[len1]+arr2[len2]+cu;
            arr3[len]=t%10;
            cu=t/=10;
            len2--;
            len1--;
            len--;
        }
        while (len1>0){
            arr3[len--]=arr1[len1--]+cu;
            cu=0;
        }
        while (len2>0){
            arr3[len--]=arr2[len2--]+cu;
            cu=0;
        }
        cur1=head;
        if(cu!=0){
            arr3[0]=cu;
            l++;
            ListNode Head=new ListNode(cu);
            Head.next=head;
            head=Head;
            cur1=head.next;
        }
int i=1;
        while(cur1!=null){
cur1.val=arr3[i++];
cur1=cur1.next;
        }
        return head;
    }


    public static String solve (String s, String t) {
      int lenMax=Math.max(s.length(),t.length());
      char[]ch=new char[lenMax];
      int lenmin=Math.min(s.length(),t.length());

int cu=0;

        for (int i = 1; i <lenmin+1 ; i++) {
            int t1= Integer.parseInt(s.substring(s.length()-i,s.length()-i+1));
            int t2= Integer.parseInt(t.substring(t.length()-i,t.length()-i+1));
         int sum=t1+t2+cu;
            ch[lenMax-i]= (char) (sum%10);
            cu=sum/10;
        }
      StringBuffer sb=new StringBuffer();
        if(cu!=0) {
        sb.append(cu);
        }
        for (int x:ch) {
            sb.append(x);
        }
String s1= String.valueOf(sb);
return s1;
    }
}


/**


    public ListNode addInList1 (ListNode head1, ListNode head2) {
long a1=0;
long a2=0;
ListNode cur1=head1;
        while(cur1!=null){
            a1=a1*10+ cur1.val;
            cur1=cur1.next;
        }
        cur1=head2;
        while(cur1!=null){
            a2=a2*10+ cur1.val;
            cur1=cur1.next;
        }
        long a3=a1+a2;
        ListNode head = null;
        while(a3!=0){
            int x= (int) (a3%10);
            ListNode l=new ListNode(x);
            if (head==null){
                head=l;
            }else {
                l.next=head;
                head=l;
            }
            a3/=10;
        }
        return  head;
    }




        public static String solve1(String s, String t) {
long x1=Long.parseLong(s);
long x2=Long.parseLong(t);
long x3=x1+x2;
return String.valueOf(x3);
    }
**/

